//
//  ZJOthersView.swift
//  Webo
//
//  Created by 曾静 on 16/6/27.
//  Copyright © 2016年 qq. All rights reserved.
//

import UIKit

import SnapKit

class ZJOthersView: UIView {
    
     private var reweetViewBottonContrast:Constraint?
    var status:ZJStatues?{
        
        didSet{
            
            textLabel.text = status?.retweeted_status?.text
            
            reweetViewBottonContrast?.uninstall()
            
            if status?.retweeted_status?.pic_urls?.count > 0 {
                
                //显示视图
                pictureView.hidden = false
                //赋值
                pictureView.status = status?.retweeted_status
                //更新约束
                self.snp_updateConstraints { (make) -> Void in
                    
                    reweetViewBottonContrast = make.bottom.equalTo(pictureView).offset(OriginalMargin).constraint
                }
                
            }else{
                //隐藏视图
                pictureView.hidden = true
                
                //更新约束
                self.snp_updateConstraints { (make) -> Void in
                    
                   reweetViewBottonContrast = make.bottom.equalTo(textLabel).offset(OriginalMargin).constraint
                }
                
            }

        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
         setupUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //创建视图
     func setupUI(){
    
//        backgroundColor = RGB(237, green: 237, blue: 237)
         addSubview(textLabel)
        
         addSubview(pictureView)
        //设置约束
        textLabel.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(self).offset(OriginalMargin)
            
            make.top.equalTo(self)
        }
        
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(textLabel)
            make.top.equalTo(textLabel.snp_bottom).offset(OriginalMargin)
        }
        
        self.snp_makeConstraints { (make) -> Void in
            
            reweetViewBottonContrast = make.bottom.equalTo(pictureView).offset(OriginalMargin).constraint
        }
    }
    
    
     private lazy var pictureView:ZJPictureView = ZJPictureView()
    private lazy var textLabel:UILabel = UILabel(textColor: UIColor.darkGrayColor(), textSize: 15, maxWidth:SCREENW - 2*OriginalMargin)
    

}
